package com.shine.controller;

import com.shine.request.MenuCreateRequest;
import com.shine.request.MenuPageRequest;
import com.shine.request.MenuUpdateRequest;
import com.shine.response.MenuResponse;
import com.shine.service.MenuService;
import com.shine.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author huihui
 * @date 2025/10/16 14:51
 * @description MenuController
 */
@Slf4j
@Tag(name = "菜单 Controller", description = "菜单 Controller")
@RestController
@RequestMapping("/menu")
public class MenuController extends BaseController {

    @Resource
    private MenuService menuService;

    @GetMapping("/list")
    @Operation(summary = "用户列表查询")
    public Result<List<MenuResponse>> listMenu(MenuPageRequest request) {
        List<MenuResponse> menuList = menuService.listMenu(request);
        return success(menuList);
    }

    @GetMapping("/delete/{id}")
    @Operation(summary = "根据ID删除菜单")
    public Result<Boolean> deleteUserById(@PathVariable("id") Long id) {
        Boolean flag = menuService.deleteById(id);
        return success(flag);
    }

    @PostMapping("/update")
    @Operation(summary = "修改菜单")
    public Result<Boolean> updateUser(@RequestBody MenuUpdateRequest request) {
        Boolean flag = menuService.updateMenu(request);
        return success(flag);
    }

    @PostMapping("/save")
    @Operation(summary = "新增菜单")
    public Result<Boolean> saveMenu(@RequestBody MenuCreateRequest request) {
        Boolean flag = menuService.saveMenu(request);
        return success(flag);
    }

}